gh-138764: annotationlib - Make call_annotate_function fallback to using VALUE annotations if both the requested format and VALUE_WITH_FAKE_GLOBALS are not implemented#138803
Conversation
… VALUE annotations
|
I also prefer this over #138788 because I think |
|
I like this too. We might need to extend the listing under https://docs.python.org/3.14/library/annotationlib.html#annotationlib.get_annotations explaining how the different formats work (and in any case, this needs a NEWS entry). |
|
I had a go at extending the descriptions of the formats. This made me realise I was describing behaviour that there wasn't a test for as a fall back so added some extra tests. |
JelleZijlstra
left a comment
There was a problem hiding this comment.
Looks good, left some small tweaks.
Accept suggestions Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Misc/NEWS.d/next/Library/2025-09-12-09-34-37.gh-issue-138764.mokHoY.rst
Outdated
Show resolved
Hide resolved
|
Thanks @DavidCEllis for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
…k to using `VALUE` annotations if both the requested format and `VALUE_WITH_FAKE_GLOBALS` are not implemented (pythonGH-138803) (cherry picked from commit 95c257e) Co-authored-by: David Ellis <ducksual@gmail.com>
|
GH-140426 is a backport of this pull request to the 3.14 branch. |
…ck to using `VALUE` annotations if both the requested format and `VALUE_WITH_FAKE_GLOBALS` are not implemented (GH-138803) (#140426) gh-138764: annotationlib: Make `call_annotate_function` fallback to using `VALUE` annotations if both the requested format and `VALUE_WITH_FAKE_GLOBALS` are not implemented (GH-138803) (cherry picked from commit 95c257e) Co-authored-by: David Ellis <ducksual@gmail.com>
…k to using `VALUE` annotations if both the requested format and `VALUE_WITH_FAKE_GLOBALS` are not implemented (python#138803)
Alternative to #138788 - instead of raising the
NotImplementedErrorthis falls back to calling an annotate function withFormat.VALUEif both the specified format andFormat.VALUE_WITH_FAKE_GLOBALSare both not implemented.I think this may be more useful behaviour than #138788 ?
If
VALUEalso fails, then the only option was failure from the start. I think it's more consistent to raise the error fromVALUEannotations in that case.Using the examples from the other PR:
On main, and with this patch:
{'x': 'str'}Main:
Patch:
{'x': 'str'}call_annotate_functionshould checkVALUE_WITH_FAKE_GLOBALSis implemented before calling in a namespace with empty fake globals #138764